package cn.han.collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

//本类用于测试ArrayList实现类
public class TestArrayList {


    public static void main(String[] args) {
        //1.创建集合对象
        ArrayList<Integer> list = new ArrayList<>();
        list.add(100);
        list.add(200);
        list.add(300);
        list.add(400);
        list.add(500);
        System.out.println(list);
        /*我们集合中存入的类型是引用类型，不是基本类型
         * 所以如果想根据元素删除数据，需要把int类型参数转为集合中元素的类型*/
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        for (Integer i :
                list) {
            System.out.println(i);
        }
        Iterator<Integer> i = list.iterator();
        while (i.hasNext()) {
            System.out.println(i.next());
        }
        ListIterator<Integer> i1 = list.listIterator();
        while (i1.hasNext()) {
            System.out.println(i1.next());
        }
        ListIterator<Integer> i2 = list.listIterator();
        while (i2.hasNext()) {
            System.out.println(i2.next());
            if (!i2.hasNext()) {

                while (i2.hasPrevious()) {//倒序
                    System.out.println(i2.previous());
                }
                break;
            }

        }
    }

}
